package com.example.mall.web.controller;

import com.example.mall.domain.UserFeedback;
import com.example.mall.dto.UserFeedbackDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.UserFeedbackQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IUserFeedbackService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userFeedback")
public class UserFeedbackController {

    @Autowired
    public IUserFeedbackService userFeedbackService;

    /**
     * 分页查询用户反馈表信息
     * @param userFeedbackQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询用户反馈表信息",notes = "分页查询用户反馈表信息",httpMethod = "GET")
    public JSONResult queryPage(UserFeedbackQuery userFeedbackQuery){
        PageDTO<UserFeedbackDto> userFeedbackDtoPageDTO = userFeedbackService.queryPage(userFeedbackQuery);
        return JSONResult.success("查询成功",userFeedbackDtoPageDTO);
    }

    /**
     * 根据id查询用户反馈表信息
     * @param feedbackId
     * @return
     */
    @GetMapping("query/{feedbackId}")
    @ApiOperation(value = "根据id查询用户反馈表信息",notes = "根据id查询用户反馈表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("feedbackId")Long feedbackId){
        //1.根据id查询用户信息
        if (feedbackId == null){
            throw new GlobalCustomerException(ErrorEnumCode.FEEDBACKID_NOT_ID);
        }
        UserFeedback userFeedback = userFeedbackService.getById(feedbackId);
        return JSONResult.success("查询成功",userFeedback);
    }

    /**
     * 根据id查询用户反馈表信息
     * @param feedbackId
     * @return
     */
    @GetMapping("queryUserFeedbackById/{feedbackId}")
    @ApiOperation(value = "根据id查询用户反馈表信息",notes = "根据id查询用户反馈表信息",httpMethod = "GET")
    public JSONResult queryUserFeedbackById(@PathVariable("feedbackId")Long feedbackId){
        //1.根据id查询用户信息
        if (feedbackId == null){
            throw new GlobalCustomerException(ErrorEnumCode.FEEDBACKID_NOT_ID);
        }
        UserFeedback userFeedback = userFeedbackService.queryUserFeedbackById(feedbackId);
        return JSONResult.success("查询成功",userFeedback);
    }

    /**
     * 查询全部用户反馈表信息
     * @param
     * @return
     */
    @GetMapping("queryUserFeedbackList")
    @ApiOperation(value = "查询全部用户反馈表信息",notes = "查询全部用户反馈表信息",httpMethod = "GET")
    public JSONResult queryUserFeedbackList(){
        List<UserFeedback> logins = userFeedbackService.queryUserFeedbackList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增用户反馈表
     * @param userFeedbackDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增用户反馈表",notes = "新增用户反馈表",httpMethod = "POST")
    public JSONResult insert(@RequestBody UserFeedbackDto userFeedbackDto){
        userFeedbackService.insert(userFeedbackDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改用户反馈表信息
     * @param userFeedbackDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改用户反馈表信息",notes = "修改用户反馈表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody UserFeedbackDto userFeedbackDto){
        userFeedbackService.update(userFeedbackDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除用户反馈表信息
     * @param feedbackId
     * @return
     */
    @PostMapping("delete/{feedbackId}")
    @ApiOperation(value = "删除用户反馈表信息",notes = "删除用户反馈表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("feedbackId") Long feedbackId) {
        userFeedbackService.delete(feedbackId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除用户反馈表信息
     * @param feedbackIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除用户反馈表信息",notes = "批量删除用户反馈表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> feedbackIds) {
        userFeedbackService.deleteBatch(feedbackIds);
        return JSONResult.success("批量删除成功");
    }
}
